/*+++++++++++++++++++++++++++++++++++++
  +                                   +
  + Autore: Davide Gugliotta          +
  + E-mail: dvd.gugliotta@gmail.com   +
  +                                   +
  + FILE: ../modules/scanner.h        +
  +                                   +
  + File header per il modulo scanner +
  +                                   +
  +++++++++++++++++++++++++++++++++++++*/
  
  #ifndef SCANNER_H
  #define SCANNER_H

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +                                                            +
  + stdio.h        libreria standard I/O                       +
  + stdlib.h       exit(),EXIT_FAILURE                         +
  + errno.h        errno                                       +
  + string.h       memset(),memcpy()                           +
  + sys/socket.h   socket()                                    +
  + netinet/in.h   struct sockaddr_in                          +
  + netdb.h        struct hostent                              +
  + netinet/tcp.h  struct tcphdr                               +
  + arpa/inet.h    htons(),htonl(),ntohs(),ntohl(),inet_pton() +
  +                                                            + 
  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

  #include <stdio.h> 
  #include <stdlib.h>
  #include <errno.h>
  #include <string.h>
  #include <sys/socket.h> 
  #include <sys/select.h>
  #include <netinet/in.h>
  #include <netdb.h>
  #include <netinet/ip.h>
  #include <netinet/tcp.h>
  #include <arpa/inet.h>


/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +                                                                +
  + Denifisco alcune costanti di utilità:                          +
  +                                                                +
  + TCP_PKT_H       lunghezza in byte header TCP 20 byte           +
  + TCP_PSEUDO_H    lunghezza in byte pseudo header TCP 12 byte    + 
  + TCP_PKT_R       lunghezza in byte MTU - HEADER IP = 1480 byte  +
  + IO_TIMEOUT_SEC  valore campo secondi timeout, 1 secondo        +
  + IO_TIMEOUT_USEC valore campo microsecondi timeout, 0.5 secondi +
  +                                                                +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 

  #define IP_PKT_H        0x14
  #define TCP_PKT_H       0x14
  #define TCP_PSEUDO_H    0x0C
  #define TCP_PKT_R       0x05C8      
  #define IO_TIMEOUT_SEC  0x01
  #define IO_TIMEOUT_USEC 0x07A120  

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +                                                                                                +
  + pkt scan è la struttura che mantiene tutte le informazioni                                     +
  + necessarie per avviare la procedura di scan:                                                   +
  +                                                                                                +
  + socket        socket creata                                                                    +
  + d_ip          struttra per gli indirizzi ipv4                                                  +
  + d_host        riferimento per la struttura che risolve l'host                                  +
  + tcp_p         riferimento per la struttura pseudo_header tcp                                   +
  + pkt_buffer    mantiene i dati TCP_PSEUDO_HEADER (12 byte ) + TCP_HEADER (20 byte)              + 
  + pkt_buffer_r  mantiene i dati di risposta al pacchetto raw inviato, MTU - HEADER IP, 1480 byte +
  +                                                                                                +
  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 

  struct pkt_scan {

    unsigned short int socket;
    struct sockaddr_in d_ip;
    struct hostent *d_host;
    struct tcphdr *tcp_p;
    unsigned char pkt_buffer[TCP_PKT_H + TCP_PSEUDO_H];
    unsigned char pkt_buffer_r[TCP_PKT_R];

  };

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +                                                                +
  + tcp_pseudo_header è la struttura che mantiene lo pseudo header +
  + per il calcolo del checksum TCP.                               +
  +                                                                +
  + ip_src    4 byte ip sorgente                                   +
  + ip_dst    4 byte ip destinazione                               +
  + zero      1 byte di zeri                                       +
  + proto     1 byte per il protocollo 6DEC tcp                    +
  + tcpht_l   2 byte lunghezza HEADER TCP + DATI                   +
  +                                                                +
  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  
  struct tcp_pseudo_header {

    unsigned int ip_src;
    unsigned int ip_dst;
    unsigned char zero;
    unsigned char proto;
    unsigned short int tcpht_l;
  
  };

  // Scanner stealth attraverso pacchet SYN //
  extern unsigned short int synscan(struct pkt_scan * , char );

  // Scanner loggabile 
  extern unsigned short int tcpscan(struct pkt_scan * );

  #endif
